#include "sysfilepathsview.h"
#include "mainwindow.h"
#include "commonfunc.h"
#include <QTreeView>

CNS_SYS_REGISTER(SysFilePathsView);

SysFilePathsView::SysFilePathsView()
{

}

void SysFilePathsView::f_start(CnsComponentPtr com)
{
    MainWindowPtr w = com->property("mainWindow").value<MainWindowPtr>();
    const QString &treeViewName = com->propertyInNs("treeViewName").toString();
    CnsStandardItemModelPtr model = com->propertyInNs("model").value<CnsStandardItemModelPtr>();
    QTreeView* tree = w->findChild<QTreeView*>(treeViewName);

    tree->setModel(model.data());

    // Demonstrating look and feel features
    tree->setAnimated(false);
    tree->setIndentation(20);
    tree->setSortingEnabled(true);
//    const QSize availableSize = QApplication::desktop()->availableGeometry(&tree).size();
//    tree->resize(availableSize / 2);
    tree->setColumnWidth(0, tree->width() / 3);

    void clicked(const QModelIndex &index);
    connect(tree, &QTreeView::clicked, tree, [com](const QModelIndex &index){
        com->exec("itemClicked", Q_ARG(const QModelIndex &, index));
    });

    tree->setWindowTitle(QObject::tr("Dir View"));
    tree->show();
}
